package com.haiwei.poi.word.bean;

import com.haiwei.poi.common.nassert.HaiweiAssert;
import com.haiwei.poi.word.exception.HaiweiBeanException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.function.Consumer;

/**
 * 对象列表迭代器.
 *
 * @date: 2022-06-27
 * @version: 1.0
 * @author: karry@haiwei.com
 */
@Data
public class HaiweiObjectArrayIterator {
    
    /**
     * 路径
     */
    private String path;
    
    /**
     * 存储数据
     */
    private HaiweiObjectArray array;
    
    /**
     * 当前访问数组元素的下标
     */
    private int index = -1;
    
    HaiweiObjectArrayIterator(HaiweiObjectArray array){
        HaiweiAssert.assertNotNull(array);
        this.array = array;
    }
    
    HaiweiObjectArrayIterator(HaiweiObjectArray array,String path){
        HaiweiAssert.assertNotNull(array);
        HaiweiAssert.assertNotNull(path);
        this.array = array;
        this.path = path;
    }
    
    /**
     * 是否遍历还有元素
     * @return
     */
    public boolean hasNext(){
        return this.array != null && array.size() > 0 && this.index < array.size();
    }
    
    /**
     * 下一个
     * @return
     */
    public HaiweiObject next(){
        if(!hasNext()){
            throw new HaiweiBeanException("array hash empty");
        }
        return this.array.get(++index);
    }
    
    public HaiweiObject current(){
        return this.array.get(this.index);
    }
   
}
